#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QToolBar>
#include <QPushButton>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //创建工具栏
    QToolBar *toolBar = new QToolBar;
    QToolBar *toolBar2 = new QToolBar;
    this->addToolBar(toolBar);
    this->addToolBar(toolBar2);

    //设置工具栏可以放置的区域
    toolBar->setAllowedAreas(Qt::LeftToolBarArea | Qt::RightToolBarArea);

    //设置工具栏不可以浮动
    toolBar->setFloatable(false);

    //设置工具栏不可移动
    toolBar2->setMovable(false);

    //创建菜单项
    QAction *action1 = new QAction("新建(&N)");
    QAction *action2 = new QAction("保存(&S)");
    QAction *action3 = new QAction("退出(&Q)");

    //为菜单添加菜单项
    ui->menu->addAction(action1);
    ui->menu->addAction(action2);
    ui->menu->addAction(action3);

    //为工具栏添加菜单项
    toolBar->addAction(action2);
    toolBar->addAction(action3);

    toolBar2->addAction(action3);
    toolBar2->addAction(action3);

    //新建一个按钮，为工具栏添加Widget
    QPushButton *button = new QPushButton("按钮");
    toolBar->addWidget(button);
    //为按钮绑定槽函数
    connect(button,&QPushButton::clicked,this,&QMainWindow::close);
}

MainWindow::~MainWindow()
{
    delete ui;
}

